import config from './libs/config.js';
import pkg from './package';

module.exports = {
  mode: 'spa',

  /**
   * 环境变量配置
   */
  env: {
    VUE_APP_VERSION: pkg.version,
    VUE_APP_TITLE: 'nuxt-app',
  },

  /**
   * 全局html头部配置
   */
  head: {
    title: pkg.name,
    meta: [
      { charset: 'utf-8' },
      { name: 'viewport', content: 'width=device-width, initial-scale=1' },
      { hid: 'description', name: 'description', content: pkg.description },
    ],
    link: [{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }],
  },

  /**
   * 加载进度条
   */
  loading: false,
  // loadingIndicator: 'wandering-cubes',

  /**
   * 全局css
   */
  css: ['~/assets/styles/index.less'],

  /**
   * 插件
   */
  plugins: ['~/plugins/vue-inject', '~/plugins/axios'],

  /**
   * Nuxt的中间件
   */
  modules: [
    // Doc: https://axios.nuxtjs.org/usage
    '@nuxtjs/axios',
    '@nuxtjs/pwa',
    '@nuxtjs/proxy',
  ],
  /**
   * Axios配置
   */
  axios: {
    baseURL: config.baseURL,
    proxy: false,
    credentials: true,
    debug: false,
  },
  /**
   * 跨域请求配置
   */
  proxy: {
    '/api': {
      target: 'http://localhost:8083',
      pathRewrite: {
        '^/api': '/',
      },
    },
  },
  /**
   * 路由配置
   */
  router: {},
  /**
   ** 构建配置
   */
  build: {
    // 自定义 webpack 加载器
    loaders: {
      less: {
        javascriptEnabled: true,
      },
    },
    // 为客户端和服务端的构建配置进行手工的扩展处理。
    extend(config, ctx) {
      // 添加ESLint规则
      if (ctx.isDev && ctx.isClient) {
        config.module.rules.push({
          enforce: 'pre',
          test: /\.(js|vue)$/,
          loader: 'eslint-loader',
          exclude: /(node_modules)/,
        });
      }
    },
  },
};
